package com.gsmr.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.gsmr.util.PropertityUtil;
import org.springframework.stereotype.Service;

import com.gsmr.dao.AlarmInfoDao;
import com.gsmr.entity.AlarmInfo;
import com.gsmr.service.AlarmInfoService;
import org.springframework.transaction.annotation.Transactional;

/**
 * AlarmInfoService实现类
 * @author alarmInfo
 *
 */
@Service("alarmInfoService")
public class AlarmInfoServiceImpl implements AlarmInfoService{

	@Resource
	private AlarmInfoDao alarmInfoDao;
	
	public List<AlarmInfo> find(Map<String, Object> map) {
		return alarmInfoDao.find(map);
	}
	public AlarmInfo findbackfill(Map<String, Object> map) {
		return alarmInfoDao.findbackfill(map);
	}

	public Long getTotal(Map<String, Object> map) {
		return alarmInfoDao.getTotal(map);
	}

	public List<AlarmInfo> findByIds(Map<String,Object> map) {
		return alarmInfoDao.findByIds(map);
	}
	
	public int update(Map<String,Object> map) {
		return alarmInfoDao.update(map);
	}

	@Override
	public List<String> get_bs_names() {		
		return alarmInfoDao.findSiteNames();
	}

	@Override
	public int updateAlarmInfo(Map<String, Object> map) {
		return alarmInfoDao.updateAlarmInfo(map);
	}

	@Override
	public Long getfrontprocessorID(Map<String, Object> map) {
		return alarmInfoDao.getfrontprocessorID(map);
	}

	@Override
	public String getSiteName(Map<String, Object> map) {
		return alarmInfoDao.getSiteName(map);
	}

	
	@Override
	public String get_frontId(Map<String, Object> map) {
		return alarmInfoDao.get_frontId(map);
	}

	@Override
	public int insertAlarmHistoryInfo(List<AlarmInfo> list) {
		 return  alarmInfoDao.insertAlarmHistoryInfo(list);
	}
	@Override
	public int deleteAlarmInfo(List<Integer> list) {
		return alarmInfoDao.deleteAlarmInfo(list);
	}
	@Override
	public List<AlarmInfo> findToAlarmHistoryInfo(Map<String, Object> map) {
		return alarmInfoDao.findToAlarmHistoryInfo(map);
	}

	@Override
	public void testTransactional(){
			Map<String, Object>map = new HashMap<>();
			map.put("table_name", "alarminfo");
			map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
			List<AlarmInfo> list= alarmInfoDao.findToAlarmHistoryInfo(map);
			if (list.size()>0) {
				System.out.println("开始插入数据到历史告警表！！！");
				int i = alarmInfoDao.insertAlarmHistoryInfo(list);
				System.out.println("结束插入数据到历史告警表！！！");
			}
			long l = System.currentTimeMillis(); //获取时间戳效率最高
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
			String format = dateFormat.format(l);
			System.out.println("睡眠开始时间==="+format);//2022-09-24
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {

				e.printStackTrace();

			}
			long m = System.currentTimeMillis(); //获取时间戳效率最高
			String format2 = dateFormat.format(m);
			System.out.println("睡眠结束时间===="+format2);//2022-09-24


			if (list.size()>0) {
				List<Integer> list_delete= new ArrayList<Integer>();
				for (AlarmInfo alarminfo:list
						) {
					list_delete.add(alarminfo.getAlarmInfoId());
				}
				System.out.println("开始删除实时告警表已处理数据！！！");
				int j = alarmInfoDao.deleteAlarmInfo(list_delete);
				System.out.println("结束删除实时告警表已处理数据！！！");
			}

	}
}
